package com.sneakxy.cloudbase.platform.service;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.sneakxy.cloudbase.platform.shiro.ShiroAccount;

public class SecurityShiroService implements IShiroService {

	@Autowired
	private IAccountService accountService;
	
	@Autowired
	private IAccountRoleService accountRoleService;
	
	@Autowired
	private IRolePermService rolePermService;
	
	@Override
	public ShiroAccount findShiroAccount(Object principal, String host) {
		return accountService.findOneByAccount((String) principal, host);
	}
	
	@Override
	public List<String> findRoles(ShiroAccount account) {
		return accountRoleService.findRoles(account.getId());
	}

	@Override
	public List<String> findPermissions(ShiroAccount account, List<String> roles) {
		return roles.isEmpty() ? Collections.emptyList() : rolePermService.findPermissions(roles);
	}

}
